<?php
/*应用程序控制类*/
class Application{
	
	public function run(){
		if (self::check_config()){
			$status = self::response();
			if ($status !== 0){
				self::halt($status);
			}
		}
	}
	
	private function response(){
		
		$GLOBALS['request'] = array(
									'module' => 'default',
									'action' => 'default',
									'parameters' => array()
									);
		
		//分析请求
		if (!empty($_GET['module'])) $GLOBALS['request']['module'] = $_GET['module'];

		if (!empty($_GET['action'])) $GLOBALS['request']['action'] = $_GET['action'];

		if (!empty($_GET['parameters'])) $GLOBALS['request']['parameters'] = explode('/',$_GET['parameters']);

		$controller_name = $GLOBALS['request']['module'].'Controller';

		//响应请求
		require_once(CTL_DIR.'/Controller.class.php');

		require_once(MDL_DIR.'/Model.class.php');

		$controller_file = CTL_DIR.'/'.$controller_name.'.class.php';

		if (file_exists($controller_file)) require_once($controller_file);
		else{
			return 1;
		}

		$control = new $controller_name();
		return $control ->$a();
	}
	
	private function halt( $error_code ){
		require_once(APP_ROOT.'Errors.php');
		echo '应用程序遇到了问题而无法继续执行！<br />';
		echo '错误代码：'.$error_code.'<br />';
		echo '错误描述：'.$errors['$error_code'];
	}
}
?>